/*  This file is part of -_-.

    -_- is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    -_- is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with -_-.  If not, see <http://www.gnu.org/licenses/>.

    Copyright 2012-2013 Oliver Katz */

#include "pair.h"
#include "../debug.h"

z_data z_pair_new(z_data f, z_data s)
{
    _z_pair tmp;
    tmp.first = f;
    tmp.second = s;
    return z_data_wrap(&tmp, Z_TYPEID_PAIR, sizeof(_z_pair));
}

z_data *_z_pair_new(z_data *f, z_data *s)
{
    Z_WARNING_DATA(f, NULL);
    Z_WARNING_DATA(s, NULL);
    z_data *tmp = (z_data *)malloc(sizeof(z_data));
    *tmp = z_pair_new(*f, *s);
    return tmp;
}

int z_pair_del(z_data *p)
{
    Z_WARNING_DATA(p, 1);
    _z_pair *tmp = (_z_pair *)z_data_src_get(p);
    Z_WARNING_PAIR(tmp, 2);
    z_data_release(tmp->first);
    z_data_release(tmp->second);
    return z_data_release(*p);
}

z_data *z_pair_first(z_data *p)
{
    Z_WARNING_DATA(p, NULL);
    _z_pair *tmp = (_z_pair *)z_data_src_get(p);
    Z_WARNING_PAIR(tmp, NULL);
    return &(tmp->first);
}

z_data *z_pair_second(z_data *p)
{
    Z_WARNING_DATA(p, NULL);
    _z_pair *tmp = (_z_pair *)z_data_src_get(p);
    Z_WARNING_PAIR(tmp, NULL);
    return &(tmp->second);
}
